
import pymysql
 
# 建立连接
conn = pymysql.connect(host='localhost',user='root',passwd='',database='haha',charset='utf8')
 
# 建立游标
c = conn.cursor()
 
# 数据库操作
# (1)定义一个格式化的sql语句
#sql = 'insert into qiushi(author,funny_num,comment_num,content) values(%s,%s,%s,%s) '
sql='''
     create table ss
     (haha char(4) primary key)
'''
# (2)准备数据
data = ('nancy','30','100','太好笑了')
# (3)操作
# try:
#     cursor.execute(sql,data)
#     conn.commit()
# except Exception as e:
#     print('插入数据失败',e)
#     conn.rollback() #回滚
c.execute(sql)

conn.commit()
# 关闭游标
c.close()
# 关闭连接
conn.close()
print("创建成功")

